#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sll.h"

void print(link p)
{
    printf("--0x%08lx--\n", p->item);
    printf("----%s----\n", (char *)(p->item));
}

void clean(link p)
{
    if (p->item)
        free((void *)p->item);
}

int main(int argc, char **argv)
{
    char *str = NULL;

    FILE *fd;
    fd = fopen("log", "rb");
    if (fd == NULL) {
        perror("file open failed.");
        exit(EXIT_FAILURE);
    }
    while ((str = malloc(80)) && fgets(str, 80, fd) != NULL) {
        printf("%s\n", str);
        link p = new_node((unsigned long)str);
        insert(p);
    }
    traverse(print);
    printf("count:%d\n", count());
    destroy(clean);
    if (fd) {
        fclose(fd);
        fd = NULL;
    }
    return 0;
}

